﻿using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RK.FormPlugin.BPW
{
    [Description("BPW:应收单整单分摊金额保存时记录行含税单价"), HotUpdate]
    public class DzReceivable : AbstractBillPlugIn
    {
        public override void BeforeSave(BeforeSaveEventArgs e)
        {
            var formId = this.View.BusinessInfo.GetForm().Id;
            if (formId == "AR_receivable")
            {
                var obj = this.Model.DataObject;
                decimal fdje = Convert.ToDecimal(obj["F_BPW_Amount"]);
                if (fdje > 0)
                {
                    DynamicObjectCollection rows = obj["AP_PAYABLEENTRY"] as DynamicObjectCollection;
                    //decimal yunZongJinE = rows.Sum(x => Convert.ToDecimal(x["FALLAMOUNTFOR_D"]));
                    for (int i = 0; i < rows.Count; i++)
                    {
                        //decimal yunJiaShuiHeJi = Convert.ToDecimal(rows[i]["FALLAMOUNTFOR_D"]);
                        //decimal xinJiaShuiHeJi = yunJiaShuiHeJi + yunJiaShuiHeJi / yunZongJinE * fdje;
                        //decimal qty = Convert.ToDecimal(rows[i]["PriceQty"]);
                        //decimal price = xinJiaShuiHeJi / qty;
                        //this.Model.SetValue("FTaxPrice", price, i);
                        //this.View.InvokeFieldUpdateService("FTaxPrice", i);
                        decimal TaxPrice = Convert.ToDecimal(rows[i]["TaxPrice"]);
                        this.Model.SetValue("FTaxPriceLog", TaxPrice, i);
                    }
                }
            }
            base.BeforeSave(e);
        }
    }
}
